--使用泰勒公式计算当前周几
--201841052073 叶佳豪
--********************************************
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
--*********************************************
ENTITY   getWeekDay  IS                                     --记得填入实体名，也是本文件名
	PORT(	                          
			 QY1:IN std_logic_vector( 3 downto 0);
			 QY2:IN std_logic_vector( 3 downto 0);
			 QY3:IN std_logic_vector( 3 downto 0);
			 QY4:IN std_logic_vector( 3 downto 0);
			 QM1:IN std_logic_vector( 3 downto 0);
			 QM2:IN std_logic_vector( 3 downto 0);
			 QD1:IN std_logic_vector( 3 downto 0);
			 QD2:IN std_logic_vector( 3 downto 0);
			 Q:OUT std_logic_vector( 3 downto 0)
		   
	    );
END getWeekDay;                                            --记得填入实体名，也是本文件名
--*********************************************
ARCHITECTURE abc OF getWeekDay IS                         --记得填入实体名，也是本文件名
signal QQ :std_logic_vector( 3 downto 0);
signal Y:INTEGER;
signal M:INTEGER;
signal M1:INTEGER;
signal D:INTEGER;
signal YY:INTEGER;
signal YU:INTEGER;

BEGIN
PROCESS(QY1,QY2,QY3,QY4,QM1,QM2,QD1,QD2)
BEGIN

Y<=(CONV_INTEGER(QY4)*1000+CONV_INTEGER(QY3)*100+CONV_INTEGER(QY2)*10+CONV_INTEGER(QY1));
M<=(CONV_INTEGER(QM2)*10+CONV_INTEGER(QM1));
D<=(CONV_INTEGER(QD2)*10+CONV_INTEGER(QD1));

END PROCESS;

PROCESS(M)
BEGIN
IF(M=1)THEN
M1<=13;
YY<=(D+2*M1+3*(M1+1)/5+(Y-1)+(Y-1)/4-(Y-1)/100+(Y-1)/400);
YU<=(YY REM 7);
ELSIF(M=2)THEN
M1<=14;
YY<=(D+2*M1+3*(M1+1)/5+(Y-1)+(Y-1)/4-(Y-1)/100+(Y-1)/400);
YU<=(YY REM 7);
ELSE
YY<=(D+2*M+3*(M+1)/5+Y+Y/4-Y/100+Y/400);
YU<=(YY REM 7);
END IF;


QQ<=CONV_STD_LOGIC_VECTOR(YU,4);


END PROCESS;
Q<=(QQ(3 DOWNTO 0)+"0001");
end abc;